#!/usr/bin/python3
# -*- encoding: utf-8 -*-
'''
@File        :test.py
@Time        :2020/08/25 14:37:52
@Author      :hejiang
@Software    :vsCode
'''

from requests import get
from requests.exceptions import RequestException
# import os
# os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'  # 解决中文乱码问题

# url = 'https://www.baidu.com'


def get_html(baseUrl):
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
    }

    # headers = {
    #     "User-Agent":
    #     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
    #     'Accept-Encoding': 'gzip, deflate',
    #     'Accept-Language': 'zh-CN,zh;q=0.9',
    #     'Accept':
    #     'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    #     'Upgrade-Insecure-Requests': '1'
    # }

    try:
        resp = get(baseUrl, headers=headers)
        # resp.encoding = 'utf-8'
        print(resp.status_code)
        if resp.status_code == 200:
            # print(resp.content)
            return resp.text
            # return resp.content
        print("没有爬取到相应的内容")
        return None
    except RequestException:
        print("没有爬取到相应的内容")
        return None


# print(get_html(url))

url = 'http://www.66ip.cn/1.html'
html = get_html(url)
print(html)
# html_doc = str(html, 'utf-8')  #html_doc=html.decode("utf-8","ignore")
# # html_doc = html.decode("utf-8", "ignore")
# print(html_doc)
